﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ProjectWizardManagementv1.Infrastructure.Abstract;

namespace ProjectWizardManagementv1.Infrastructure.Concrete
{
    public class ComputerFileSystem : IFileSystem
    {
        public void DirectoryMove(string oldPath, string newPath)
        {
            Directory.Move(oldPath, newPath);
        }

        public void FileMove(string oldPath, string newPath)
        {
            File.Move(oldPath, newPath);
        }

        public void FileCopy(string sourceFileName, string destFileName, bool overwrite = false)
        {
            File.Copy(sourceFileName, destFileName, overwrite);
        }

        public void FileDelete(string path)
        {
            File.Delete(path);
        }

        public void DirectoryDelete(string path)
        {
            var files = Directory.GetFiles(path);
            var directories = Directory.GetDirectories(path);

            foreach (var file in files)
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
            }

            foreach (var directory in directories)
                DirectoryDelete(directory);

            try
            {
                Directory.Delete(path);
            }
            catch (IOException)
            {
            }
        }

        public bool FileExists(string path)
        {
            return File.Exists(path);
        }

        public bool DirectoryExists(string path)
        {
            return Directory.Exists(path);
        }

        public bool FileOrDirectoryExists(string path)
        {
            return DirectoryExists(path) || FileExists(path);
        }
    }
}
